﻿//-----------------------------------------------------------------------
// <copyright file="FileHelperTest.cs" company="Panchal Softwares">
//     Copyright (c) Panchal Softwares. All rights reserved.
// </copyright>
// <author>Karn Panchal</author>
//-----------------------------------------------------------------------

/// <summary>
/// Namespace Text Finder Unit Test.
/// </summary>
namespace PanchalSoftwares.TextFinder.UnitTest
{
    using System;
    using System.IO;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using PanchalSoftwares.TextFinder.Library;

    /// <summary>
    /// Class File Helper Test.
    /// </summary>
    [TestClass]
    public class FileHelperTest
    {
        /// <summary>
        /// Tests the file helper.
        /// </summary>
        [TestMethod]
        public void TestFindFiles()
        {
            string path = Path.Combine(Environment.CurrentDirectory, "TestFile1.txt");
            string extension = "txt";
            StreamWriter writer = new StreamWriter(path);
            writer.Write("Test");
            writer.Flush();
            writer.Close();
            Assert.AreEqual(FileHelper.FindFiles(Environment.CurrentDirectory, extension).Count > 0, true);
            Assert.AreEqual(FileHelper.FindFiles(@"C:\", extension).Count > 0, false);
        }

        /// <summary>
        /// Tests the is text available.
        /// </summary> 
        [TestMethod]
        public void TestIsTextAvailable()
        {
            string path = Path.Combine(Environment.CurrentDirectory, "TestFile2.txt");
            StreamWriter writer = new StreamWriter(path);
            writer.Write("Test");
            writer.Flush();
            writer.Close();
            FileInfo fileInfo = new FileInfo(path);
            Assert.AreEqual(FileHelper.IsTextAvailable(fileInfo, "Any"), false);
            Assert.AreEqual(FileHelper.IsTextAvailable(fileInfo, "Test"), true);
            FileHelper.UseCaseSensitiveSearch = true;
            Assert.AreEqual(FileHelper.IsTextAvailable(fileInfo, "Any"), false);
            Assert.AreEqual(FileHelper.IsTextAvailable(fileInfo, "Test"), true);
        }

        /// <summary>
        /// Tests the find files with text.
        /// </summary>
        [TestMethod]
        public void TestFindFilesWithText()
        {
            string extension = "txt";
            string text = "Test";
            string path = Path.Combine(Environment.CurrentDirectory, "TestFile3.txt");
            StreamWriter writer = new StreamWriter(path);
            writer.Write(text);
            writer.Flush();
            writer.Close();
            Assert.AreEqual(FileHelper.FindFiles(Environment.CurrentDirectory, extension, text).Count > 0, true);
        }
    }
}
